﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace Meraz.Web.Views.Helpers
{
    public static class SiteHelper
    {
        public static string AddNewBox(string label)
        {
            return AddNewBox(label, "AddInput");
        }
        public static string AddNewBox(string label, string id)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine("<div class='addPanel ui-widget'>");
            builder.AppendFormat("<label for='{0}'>{1}</label>", id, label);
            builder.AppendFormat("<input id='{0}' name='{0}' type='text' />", id);
            builder.AppendFormat(@"<button class='add' type='button' onclick='window.PageBus.publish(""table.add.datatable"", ""{0}"");'>Add</button>", id);
            builder.AppendLine("</div>");
            return builder.ToString();
        }
        public static string CheckboxButton(this HtmlHelper html, string id, string label, bool isSelected)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("<input type='checkbox' id='{0}' name='{0}' value='{0}' ", id);
            if (isSelected)
                builder.Append("checked='true' ");
            builder.AppendFormat(" /><label for='{0}'>{1}</label>", id, label);
            builder.AppendLine();
            return builder.ToString();
        }
        public static string RadioButtonList(string group, IEnumerable<string> values, string selectedValue)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine();
            foreach(string name in values)
            {
                builder.AppendFormat(@"<input type='radio' class='button' id='{0}-{1}' name='{0}' value='{1}'", group, name);
                if (name.Equals(selectedValue))
                    builder.Append(" checked='true'");
                builder.Append(" />");
                builder.AppendFormat(@"<label for='{0}-{1}'>{1}</label>", group, name);
                builder.AppendLine();
            }
            return builder.ToString();
        }
    }
}